package com.tanhua.server.contoller;

import com.tan.model.domain.User;
import com.tan.model.domain.UserInfo;
import com.tanhua.server.interceptor.Userthread;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserInfoService userInfoService;
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo, @RequestHeader("Authorization") String token){

//        //1、解析token
//        Claims verifytoken = JwtUtils.verify(token);
//        if (verifytoken != null){
//       Integer id = (Integer)   verifytoken.get("id");
        User user = Userthread.getUser();

       Long idL= user.getId();
       userInfo.setId(idL);
            //3、调用service
            userInfoService.save(userInfo);
            return ResponseEntity.ok(null);

    }
    @PostMapping("/loginReginfo/head")
    public ResponseEntity Headimage(MultipartFile headPhoto,@RequestHeader("Authorization")String token) throws IOException {

//        Claims verify = JwtUtils.verify(token);
//        Integer id = (Integer) verify.get("id");
        Long id= Userthread.getUser().getId();
        userInfoService.update(headPhoto,id);
        return ResponseEntity.ok(null);
    }

}
